#include <algorithm>
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int ans = INT_MAX;
        int i = 0,sum=0,j=0;
        while(i<nums.size())
        {
            sum += nums[i];
            while (sum >= target)
            {
                ans = min(ans, i - j + 1);
                sum -= nums[j];
                j++;
            }
                i++;
        }
        return ans == INT_MAX ? 0 : ans;
    }
};